#pragma once

//#include <srs_app_http_hooks.hpp>
#include <srs_core.hpp>

#include <string>

#ifdef SRS_AUTO_HTTP_CALLBACK

#include <http_parser.h>

class SrsHttpUri;
class SrsStSocket;
class SrsRequest;
class SrsHttpParser;
class SrsFlvSegment;

/**
* the http hooks, http callback api,
* for some event, such as on_connect, call
* a http api(hooks).
*/
class SrsHttpHooks {
private:
    SrsHttpHooks();
public:
    virtual ~SrsHttpHooks();
public:
    /**
    * on_connect hook, when client connect to srs.
    * @param url the api server url, to valid the client.
    *         ignore if empty.
    */
    static int on_connect(const std::string& url, SrsRequest* req);
    /**
    * on_close hook, when client disconnect to srs, where client is valid by on_connect.
    * @param url the api server url, to process the event.
    *         ignore if empty.
    */
    static void on_close(const std::string& url, SrsRequest* req, int64_t send_bytes, int64_t recv_bytes);
    /**
    * on_publish hook, when client(encoder) start to publish stream
    * @param url the api server url, to valid the client.
    *         ignore if empty.
    */
    static int on_publish(const std::string& url, SrsRequest* req, std::string& resp);
    /**
    * on_unpublish hook, when client(encoder) stop publish stream.
    * @param url the api server url, to process the event.
    *         ignore if empty.
    */
    static void on_unpublish(const std::string& url, SrsRequest* req);
    /**
    * on_play hook, when client start to play stream.
    * @param url the api server url, to valid the client.
    *         ignore if empty.
    */
    static int on_play(const std::string& url, SrsRequest* req);
    /**
    * on_stop hook, when client stop to play the stream.
    * @param url the api server url, to process the event.
    *         ignore if empty.
    */
    static void on_stop(const std::string& url, SrsRequest* req);
    /**
     * on_dvr hook, when reap a dvr file.
     * @param url the api server url, to process the event.
     *         ignore if empty.
     * @param file the file path, can be relative or absolute path.
     * @param cid the source connection cid, for the on_dvr is async call.
     */
    static int on_dvr(int cid, const std::string& url, SrsRequest* req, const std::string& file);
    /**
     * when hls reap segment, callback.
     * @param url the api server url, to process the event.
     *         ignore if empty.
     * @param file the ts file path, can be relative or absolute path.
     * @param ts_url the ts url, which used for m3u8.
     * @param m3u8 the m3u8 file path, can be relative or absolute path.
     * @param m3u8_url the m3u8 url, which is used for the http mount path.
     * @param sn the seq_no, the sequence number of ts in hls/m3u8.
     * @param duration the segment duration in seconds.
     * @param cid the source connection cid, for the on_dvr is async call.
     */
    static int on_hls(int cid, const std::string& url, SrsRequest* req, const std::string& file, std::string& ts_url,
                      const std::string& m3u8, const std::string& m3u8_url, int sn, double duration);
    /**
     * when hls reap segment, callback.
     * @param url the api server url, to process the event.
     *         ignore if empty.
     * @param ts_url the ts uri, used to replace the variable [ts_url] in url.
     * @param nb_notify the max bytes to read from notify server.
     * @param cid the source connection cid, for the on_dvr is async call.
     */
    static int on_hls_notify(int cid, std::string& url, SrsRequest* req, const std::string& ts_url, int nb_notify);
public:
    static int do_post(const std::string& url, const std::string& req, int& code, std::string& res);
};

#endif
